package wsi.match;

import org.rygh.core.face.IHasKey;
import org.rygh.semantic.model.rdf.Predicate;

import wsi.dataguide.tree.WSXmlLeaf;
import wsi.subgraph.entity.XmlEntityPair;
import wsi.subgraph.tree.EntityLeaf;
import wsi.subgraph.tree.EntityObject;

public class MatchPair extends XmlEntityPair implements IHasKey<String> {

	private final String key;
	private boolean superNode;
	private double confidence = 1;

	public MatchPair(WSXmlLeaf leaf, EntityLeaf node) {
		super(leaf, node);
		this.key = generateKey();
		superNode = false;
	}

	private String generateKey() {
		EntityObject obj = getEntityLeaf().getValue();
		Predicate pred = obj.getPredicate();

		return String.format("%s = %s%s", getXmlLeaf().getXpath().stripIndex(),
				pred.getValue(), pred.getInverseSuffix());
	}

	public double getConfidence() {
		return confidence;
	}

	@Override
	public String getKey() {
		return key;
	}

	public boolean isSuperNode() {
		return superNode;
	}

	public void setConfidence(double confidence) {
		this.confidence = confidence;
	}

	public void setSuperNode(boolean superNode) {
		this.superNode = superNode;
	}

	@Override
	public String toString() {
		return String.format("(node %s<-(%s)%s, leaf %s)", getEntityLeaf().getValue()
				.getValue(), getEntityLeaf().getValue().getPredicate(), getEntityLeaf()
				.getParent().getValue().getValue(), getXmlLeaf().getXpath());
	}
}
